package com.dd.ms.provider.web.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dd.ms.log.api.pojo.dto.LogEntryDTO;
import com.dd.ms.log.api.pojo.enumuration.LogLevelEnum;
import com.dd.ms.mw.kafka.utils.KafkaProducerUtil;
import com.dd.ms.provider.api.DataObjectFeignClient;
import com.dd.ms.provider.pojo.DataObjectBO;
import com.dd.ms.provider.pojo.req.DataObjectPageQueryReq;
import com.dd.ms.provider.web.service.internal.DataObjectServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.Instant;

/**
 * @Author liuxianmeng
 * @CreateTime 2025/3/11 6:39
 * @Description DataObjectController
 */
@Slf4j
@RestController
@Api(tags = "数据对象管理")
@RequiredArgsConstructor
@RequestMapping("/data-object")
public class DataObjectController implements DataObjectFeignClient {

    @Value("${spring.application.name}")
    private String appServiceName;

    private final DataObjectServiceImpl dataObjectServiceImpl;

    @Override
    @PostMapping("/page")
    @ApiOperation("分页获取DataObjectBO信息")
    public Page<DataObjectBO> pageFeign(@RequestBody DataObjectPageQueryReq req) {
        // 日志发送测试
        KafkaProducerUtil.sendMessage(
                KafkaProducerUtil.systemLogTopic,
                LogEntryDTO.builder()
                        .message(req.toString())
                        .level(LogLevelEnum.INFO.name())
                        .serviceName(appServiceName)
                        .timestamp(Instant.now())
                        .build()
        );
        return dataObjectServiceImpl.pageFeign(req);
    }
}
